package com.dapeis.domain;

import java.util.Date;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.ag.core.base.Domain;
import com.dapeis.core.utils.StringUtil;
import com.dapeis.core.utils.StylistConstants;

/**
 * @author 作者 E-mail: hzyuanyong@126.com
 * @version 创建时间：2017年5月11日 下午8:52:42 评论表
 */
@Table(name = "dps_comment")
public class Comment extends Domain {

    private static final long serialVersionUID = 8755055784221649442L;

    @Id
    @GeneratedValue(generator = "JDBC")
    Integer id;
    Integer userId;
    Long orderId;
    Integer requirementId;
    Integer planId;// 方案ID
    Long createTime;
    String type; // 类型,订单或方案
    String score;// 评分
    String content;// 内容
    Integer state = StylistConstants.State.NORMAL;

    
    public static final String PROPERTY_PLANID = "planId";
    public static final String PROPERTY_TYPE = "type";
    public static final String PROPERTY_CREATETIME = "createTime";
   
    
    public Integer getId() {
	return id;
    }

    public void setId(Integer id) {
	this.id = id;
    }

    public Integer getUserId() {
	return userId;
    }

    public void setUserId(Integer userId) {
	this.userId = userId;
    }

    public Long getOrderId() {
	return orderId;
    }

    public void setOrderId(Long orderId) {
	this.orderId = orderId;
    }

    public Integer getRequirementId() {
	return requirementId;
    }

    public void setRequirementId(Integer requirementId) {
	this.requirementId = requirementId;
    }

    public Long getCreateTime() {
	return createTime;
    }

    public void setCreateTime(Long createTime) {
	this.createTime = createTime;
    }

    public String getScore() {
	return score;
    }

    public void setScore(String score) {
	this.score = score;
    }

    public String getContent() {
	return content;
    }

    public void setContent(String content) {
	this.content = content;
    }

    public Integer getState() {
	return state;
    }

    public void setState(Integer state) {
	this.state = state;
    }

    /**
     * 订单评论
     */
    @Transient
    public Comment buildComment(Long orderId, Integer userId,
	    Integer requiremntId, String score, String content) {
	Comment comment = this;
	comment.setContent(content);
	comment.setCreateTime(new Date().getTime() / 1000);
	comment.setOrderId(orderId);
	comment.setRequirementId(requiremntId);
	comment.setScore(score);
	comment.setUserId(userId);
	comment.setType(StylistConstants.CommentType.ORDER);
	return comment;
    }

    /**
     * 方案评价
     */
    @Transient
    public Comment buildCommentPlan(Integer userId, String content,
	    Integer planId) {
	Comment comment = this;
	comment.setContent(content);
	comment.setPlanId(planId);
	comment.setCreateTime(new Date().getTime() / 1000);
	comment.setUserId(userId);
	comment.setType(StylistConstants.CommentType.PLAN);
	return comment;
    }

    @Transient
    public static boolean checkScoreValue(String score) {
	if (StringUtil.isBlank(score)) {
	    return false;
	}
	// 12345为分值
	return "12345".indexOf(score) >= 0;
    }

    public Integer getPlanId() {
	return planId;
    }

    public void setPlanId(Integer planId) {
	this.planId = planId;
    }

    public String getType() {
	return type;
    }

    public void setType(String type) {
	this.type = type;
    }

}
